package com.qkl.xiatang.app.web.controller;

import com.qkl.xiatang.app.dto.feed.WeighGroupQtyInDTO;
import com.qkl.xiatang.app.service.feed.FeedWeighService;
import com.qkl.xiatang.app.utils.AppUtils;
import com.qkl.xiatang.app.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("{app.baseURL}")
@Slf4j
public class FeedWeighController {

    @Autowired
    private FeedWeighService feedWeighService;

    /**
     * 查询称饲料任务按重量分组
     * @param params
     * @return
     */
    @PostMapping("/queryWeighGroupQty")
    public Result queryMessageList(@RequestBody WeighGroupQtyInDTO params) {
        return ControllerHelper.toQueryResult(feedWeighService.queryWeighGroupQty(params));
    }

    /**
     * 查询称饲料任务按重量分组-明细
     * @param params
     * @return
     */
    @GetMapping("/queryWeighGroupQtyDetail")
    public Result queryWeighGroupQtyDetail(@RequestParam Map<String,String> params) {
        String pageIndex = StringUtils.trimToEmpty(params.get("pageIndex"));
        String pageSize = StringUtils.trimToEmpty(params.get("pageSize"));
        String taskIdStrings = StringUtils.trimToEmpty(params.get("taskIdStrings"));

        WeighGroupQtyInDTO dto = new WeighGroupQtyInDTO();
        dto.setPageIndex(AppUtils.parseInt(pageIndex));
        dto.setPageSize(AppUtils.parseInt(pageSize));
        dto.setTaskIdStrings(taskIdStrings);
        return ControllerHelper.toQueryResult(feedWeighService.queryWeighGroupQtyDetail(dto));
    }

    /**
     * 按重量完成称饲料任务
     * @param params
     * @return
     */
    @PostMapping("/finishWeighGroupQty")
    public Result finishWeighGroupQty(@RequestBody Map<String,String> params) {
        String taskIdStrings = StringUtils.trimToEmpty(params.get("taskIdStrings"));
        WeighGroupQtyInDTO dto = new WeighGroupQtyInDTO();
        dto.setTaskIdStrings(taskIdStrings);
        return ControllerHelper.toOperateResult(feedWeighService.finishWeighGroupQty(dto));
    }

    /**
     * 按重量取消称饲料任务
     * @param params
     * @return
     */
    @PostMapping("/cancelWeighGroupQty")
    public Result cancelWeighGroupQty(@RequestBody Map<String,String> params) {
        String taskIdStrings = StringUtils.trimToEmpty(params.get("taskIdStrings"));
        WeighGroupQtyInDTO dto = new WeighGroupQtyInDTO();
        dto.setTaskIdStrings(taskIdStrings);
        return ControllerHelper.toOperateResult(feedWeighService.cancelWeighGroupQty(dto));
    }

    /**
     * 查询称饲料餐次
     * @return
     */
    @GetMapping("/queryWeighMeal")
    public Result queryWeighMeal() {
        return ControllerHelper.toQueryResult(feedWeighService.queryWeighMeal());
    }

}
